package com.example.android.courtcounter;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    int teamAScore = 0;
    int teamBScore = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public void displayForTeamA(int score) {
        TextView scoreView = (TextView) findViewById(R.id.team_a_score);
        scoreView.setText(String.valueOf(score));
    }

    public void displayForTeamB(int score) {
        TextView scoreView = (TextView) findViewById(R.id.team_b_score);
        scoreView.setText(String.valueOf(score));
    }

    public void addThreePointsForA(View view) {
        clickAddThreePoints("A");
        displayForTeamA(teamAScore);
    }

    public void addTwoPointsForA(View view) {
        clickAddTwoPoints("A");
        displayForTeamA(teamAScore);
    }

    public void addOnePointForA(View view) {
        clickAddOnePoint("A");
        displayForTeamA(teamAScore);
    }

    public void addThreePointsForB(View view) {
        clickAddThreePoints("B");
        displayForTeamB(teamBScore);
    }

    public void addTwoPointsForB(View view) {
        clickAddTwoPoints("B");
        displayForTeamB(teamBScore);
    }

    public void addOnePointForB(View view) {
        clickAddOnePoint("B");
        displayForTeamB(teamBScore);
    }

    public void reset(View view) {
        teamAScore=0;
        teamBScore=0;
        displayForTeamA(teamAScore);
        displayForTeamB(teamBScore);
    }

    private void clickAddThreePoints(String team) {
        if (team == "A") {
            teamAScore = teamAScore + 3;
        } else if (team == "B") {
            teamBScore = teamBScore + 3;
        }
    }

    private void clickAddTwoPoints(String team) {
        if (team == "A") {
            teamAScore = teamAScore + 2;
        } else if (team == "B") {
            teamBScore = teamBScore + 2;
        }
    }

    private void clickAddOnePoint(String team) {
        if (team == "A") {
            teamAScore = teamAScore + 1;
        } else if (team == "B") {
            teamBScore = teamBScore + 1;
        }
    }


}
